package com.example.share_doc.controller;

import com.example.share_doc.controller.dto.DepartmentDto;
import com.example.share_doc.controller.dto.DepartmentQueryDto;
import com.example.share_doc.entity.Department;
import com.example.share_doc.entity.User;
import com.example.share_doc.service.DepartmentService;
import com.example.share_doc.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/department")
@Tag(name = "部门接口")
public class DepartmentController {

    private DepartmentService departmentService;

    @PostMapping("/queryList")
    @Operation(summary = "部门一览")
    public R departmentQueryList(DepartmentQueryDto departmentQueryDto){
        List<DepartmentDto> departmentTree = departmentService.queryList(departmentQueryDto);
        return R.success(departmentTree);
    }

    @GetMapping("/queryUserList")
    @Operation(summary = "部门成员列表")
    public R departmentQueryUserList(String departmentCode){
        List<User> departmentUserList = departmentService.queryUserList(departmentCode);
        return R.success(departmentUserList);
    }

    @PostMapping("/addOrUpdate")
    @Operation(summary = "新增部门")
    public R departmentAddOrUpdate(Department department){
        departmentService.departmentAddOrUpdate(department);
        return R.success(null);
    }

    @PostMapping("/deleteList")
    @Operation(summary = "删除部门")
    public R departmentDeleteList(@RequestParam List<String> departmentIdList){
        departmentService.departmentDeleteList(departmentIdList);
        return R.success(null);
    }
}
